package com.frxuexi.soufang

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.db.HourseDao
import com.frxuexi.lib_base.entity.HourseDBBean
import com.frxuexi.lib_base.entity.HourseDetailBean
import com.frxuexi.lib_base.entity.HourseHomeBean
import com.frxuexi.lib_base.entity.HourseMenu
import com.frxuexi.lib_base.entity.NewHourseBean
import com.frxuexi.lib_base.entity.OldHourseBean
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.net.HourseApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class HourseViewModel @Inject constructor(val apiService: HourseApiService,val hourseDao: HourseDao):BaseViewModel() {
    var hourseSuc = MutableLiveData<HourseHomeBean>()
    var hourseMenuSuc = MutableLiveData<HourseMenu>()
    var oldHourseSuc = MutableLiveData<OldHourseBean>()
    var newHourseSuc = MutableLiveData<NewHourseBean>()
    var hourseDetailSuc = MutableLiveData<HourseDetailBean>()

    var addHourseSuc = MutableLiveData<Long>()
    var deleteHourseSuc = MutableLiveData<Int>()

    var selectSCSuc = MutableLiveData<Int>()

    var selectHourseSuc = MutableLiveData<List<HourseDBBean>>()
    fun getHourseHome(){
        httpRequestHourse({apiService.getHourseHome()},hourseSuc::postValue)
    }

    fun getHourseMenu(){
        httpRequestHourse({apiService.getHomeMenu()},hourseMenuSuc::postValue)
    }

    fun getOldHourse(){
        httpRequestHourse({apiService.getOldHourse()},oldHourseSuc::postValue)
    }
    fun getNewHourse(){
        httpRequestHourse({apiService.getNewHourse()},newHourseSuc::postValue)
    }

    fun getHourseDetail(id:Int){
        httpRequestHourse({apiService.getHoiurseDetail(id)},hourseDetailSuc::postValue)
    }

    fun addHourse(hourseDBBean: HourseDBBean){
        roomRequest({hourseDao.addHourse(hourseDBBean)},addHourseSuc::postValue)
    }

    fun deleteHourse(hourseDBBean: HourseDBBean){
        roomRequest({hourseDao.deleteHourse(hourseDBBean)},deleteHourseSuc::postValue)
    }

    fun selectSC(id:Int){
        roomRequest({hourseDao.selectSC(id)},selectSCSuc::postValue)
    }

    fun selectHourse(){
        roomRequest({hourseDao.selectHourse()},selectHourseSuc::postValue)
    }
}